-
Notifications
You must be signed in to change notification settings - Fork 760
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wrap_x: change macros back to macro_rules!
#2363
Conversation
src/macros.rs
Outdated
#[macro_export] | ||
macro_rules! wrap_pyfunction { | ||
($function:path) => { | ||
&|arg| { | ||
use $function as def; | ||
$crate::impl_::pyfunction::wrap_pyfunction(def::DEF, arg) | ||
} | ||
}; | ||
($function:path, $arg:expr) => {{ | ||
use $function as def; | ||
$crate::impl_::pyfunction::wrap_pyfunction(def::DEF, $arg) | ||
}}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO it is kinda weird that there are two ways to invoke the macro. (I know it did this before, this is somewhat off-topic). AFAIK the first branch is only for use with add_wrapped
, right?
I've seen several people get confused by this macro, so if there's a chance to simplify it I'd like to take it. But at least that should be documented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with this, but I'd like to avoid making changes to meet these points in this PR... let me try to push an experiment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #2367 as the way I hope we eventually can get rid of the wrap macroa for good.
src/macros.rs
Outdated
($function:path, $arg:expr) => {{ | ||
use $function as def; | ||
$crate::impl_::pyfunction::wrap_pyfunction(def::DEF, $arg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
($function:path, $arg:expr) => {{ | |
use $function as def; | |
$crate::impl_::pyfunction::wrap_pyfunction(def::DEF, $arg) | |
($function:path, $module:expr) => {{ | |
use $function as def; | |
$crate::impl_::pyfunction::wrap_pyfunction(def::DEF, $module) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will go for module_or_py
(because those are the things it can be, IIRC).
2199315
to
cca0e0b
Compare
3463942
to
321cbff
Compare
Hmm this runs into trouble with glob imports because the macro rules are slightly wonky with paths... see rust-lang/rust#48067 |
Actually a slight bit of breakage related to glob imports of submodules with the same name as the containing Rust module seems inevitable but perhaps better behaviour overall - see #2366 (comment) I think this case should be pretty rare so think it's fine to proceed. |
321cbff
to
39ab95a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
39ab95a
to
7a9e70e
Compare
Marginal cleanup to convert the
wrap_pyfunction
andwrap_pymodule
macros back tomacro_rules!
macros.I think it's marginally easier for both readers and maintainers to follow
macro_rules!
macros in this simple case. Also allows for better doc links.